#include<iostream>
#include<cstdio>
using namespace std;
int n,m,b[10000],sum;
int getf(int i){
	if(b[i]==i)return i;
	else {
		b[i]=getf(b[i]); 
	}
	return b[i];
}
void merge(int x,int y){
	int t1=getf(x),t2=getf(y);
	if(t1!=t2){
		b[t2]=b[t1];
	}
	return;
}
int main(){
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++){
		b[i]=i;
	}
	for(int x,y,i=1;i<=m;i++){
		scanf("%d%d",&x,&y);
		merge(x,y);
	}
	for(int i=1;i<=n;i++){
		if(b[i]==i)sum++;
	}
	cout<<sum;
}
